#include <string.h>
#include "mips-regdef.h"
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))

const char* regname[] = {
        "zero","at","v0","v1",
        "a0",  "a1","a2","a3",
        "t0",  "t1","t2","t3",
        "t4",  "t5","t6","t7",
        "s0",  "s1","s2","s3",
        "s4",  "s5","s6","s7",
        "t8",  "t9","k0","k1",
        "gp",  "sp","fp","ra",
        "hi",  "lo",
        "f0" ,"f1" ,"f2" ,"f3" ,
        "f4" ,"f5" ,"f6" ,"f7" ,
        "f8" ,"f9" ,"f10","f11",
        "f12","f13","f14","f15",
        "f16","f17","f18","f19",
        "f20","f21","f22","f23",
        "f24","f25","f26","f27",
        "f28","f29","f30","f31",
        "fcr31"

};
const int regname_size = ARRAY_SIZE(regname);
const int gregs_num[] = {
     0, 1, 2, 3, 4, 5, 6, 7,
     8, 9,10,11,12,13,14,15,
    16,17,18,19,20,21,22,23,
    24,25,26,27,28,29,30,31
};

const int gregs_args_num[] = {4, 5, 6, 7};
const int gregs_ret_num[] = {2,3};
const int gregs_caller_num[] = {8, 9, 10, 11, 12, 13, 14, 15,24,25};
const int gregs_callee_num[] = {16,17,18,19,20,21,22,23};
const int gregs_jp = 25;
const int gregs_gp = 28;
const int gregs_sp = 29;
const int gregs_fp = 30;
const int gregs_ra = 31;
const int gregs_hi = 32;
const int gregs_lo = 33;

const int fregs_num[] = {
    34,35,36,37,38,39,40,41,
    42,43,44,45,46,47,48,49,
    50,51,52,53,54,55,56,57,
    58,59,60,61,62,63,64,65
};

#define FREG_NUM(x) (34 + x)
const int fregs_ret_num[] = {FREG_NUM(0), FREG_NUM(1), FREG_NUM(2),
                             FREG_NUM(3)};

const int fregs_args_num[] = {FREG_NUM(12), FREG_NUM(13), FREG_NUM(14),
                             FREG_NUM(15)};

const int fregs_caller_num[] = {
    FREG_NUM(4), FREG_NUM(5), FREG_NUM(6), FREG_NUM(7),
    FREG_NUM(8), FREG_NUM(9), FREG_NUM(10), FREG_NUM(11),
    FREG_NUM(16), FREG_NUM(17), FREG_NUM(18), FREG_NUM(19),
    };

const int fregs_callee_num[] = {
    FREG_NUM(20), FREG_NUM(21), FREG_NUM(22), FREG_NUM(23),
    FREG_NUM(24), FREG_NUM(25), FREG_NUM(26), FREG_NUM(27),
    FREG_NUM(28), FREG_NUM(29), FREG_NUM(30), FREG_NUM(31),
};

const int freg_cr_reg = 66;

struct greg_num mips_greg_num = {
    .num = gregs_num,
    .nums = ARRAY_SIZE(gregs_num),
    .ret = gregs_ret_num,
    .rets = ARRAY_SIZE(gregs_ret_num),
    .arg = gregs_args_num,
    .args = ARRAY_SIZE(gregs_args_num),
    .caller = gregs_caller_num,
    .callers = ARRAY_SIZE(gregs_caller_num),
    .callee = gregs_callee_num,
    .callees = ARRAY_SIZE(gregs_callee_num),
    .jp = gregs_jp,
    .gp = gregs_gp,
    .sp = gregs_sp,
    .fp = gregs_fp,
    .ra = gregs_ra,
    .hi = gregs_hi,
    .lo = gregs_lo
};

struct freg_num mips_freg_num = {
    .num = fregs_num,
    .nums = ARRAY_SIZE(fregs_num),
    .ret = fregs_ret_num,
    .rets = ARRAY_SIZE(fregs_ret_num),
    .arg = fregs_args_num,
    .args = ARRAY_SIZE(fregs_args_num),
    .caller = fregs_caller_num,
    .callers = ARRAY_SIZE(fregs_caller_num),
    .callee = fregs_callee_num,
    .callees = ARRAY_SIZE(fregs_callee_num),
    .cr = freg_cr_reg,
};
